<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>clearfix同时解决高度塌陷和外边距重叠问题</title>
</head>
<style>
    .box1 {
        background-color: aqua;
    }
    .box2{
        width: 100px;
        height: 100px;
        background-color: red;
        margin-top: 100px;
        float: left;
    }
    .box4{
        width: 100px;
        height: 100px;
        background-color: red;
        float: left;
    }
    .box3{
        width: 100px;
        height: 100px;
        background-color: black;
    }
    .clearfix::before,
    .clearfix::after{
        content: "";
        display: table;
        clear: both;
    }
</style>
<body>
<div class="box1 clearfix">
    <div class="box2">

    </div>
    <div class="box4">

    </div>
</div>
<div class="box3">

</div>
</body>
</html>